<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css"></style>
</head>
<body>
    <h1>JS表单事件</h1>
    <hr>

    <input type="text" id="s" value="请输入搜索内容..." placeholder="请输入搜索内容..." style="color:#ccc">
    <br>
    <br>
    <br>
    <hr>


    <h3>说点什么: </h3>
    <textarea id="weibo" cols="30" rows="5" placeholder="请输入140字的内容.." maxlength="140" onkeyup="check(this)"></textarea>

    <p>
        您还能输入: <font color="#f00" size="6" id="ts">140</font> 个字!
    </p>

    <script>
        var input = document.getElementById('s');
        input.onfocus = function() {
            // console.log(' 或叫了');
            this.value = '';
            this.style.color = '#000';
        }

        // 实时监测输入字数长度
        var ts = document.getElementById('ts');
        num = 140;

        function check(obj){
            // console.log(obj.value.length);
            var n = obj.value;
            var lengths = num - n.length;
            ts.innerHTML = lengths;
        }



    </script>
</body>
</html>